/*
 * logapi.h
 *
 *  Created on: 2011-3-8
 *      Author: minorityee
 */

#ifndef LOGAPI_H_
#define LOGAPI_H_

#include "common_type.h"
#include "common_def.h"
#include <stdarg.h>

#define LOGLV_TO_STR(enumLogLv) arrLogLevelStr[enumLogLv]

typedef enum tagLogLevel 
{
	enmLogLevel_INVALID	= 0,	//invalid log level
	enmLogLevel_DEBUG 	= 1,
	enmLogLevel_INFO	= 2,
	enmLogLevel_WARN	= 3,
	enmLogLevel_ERROR	= 4,
	enmLogLevel_FATAL	= 5,
	enmLogLevel_END
}LogLevel;

enum 
{
	enmMaxLogFilePrefixMaxLen	= 32,
	enmMaxLogFileNameLen 		= 256,
	enmMaxLogFullPathLen		= 256,
	enmMaxLogPrefixLen			= MAX_DATETIME_LEN + 10 + 1, //%04d-%02d-%02d %02d:%02d:%02d %s
	enmMaxLogLen 				= 0x00010000U,
	enmMaxLogFileSize			= 0x00100000U,
};

#define DECLARE_LOGLEVEL_STR(NAME)	\
const char* NAME[] =	\
{		"",				\
		"[DEBUG]   ",	\
		"[INFO]    ",	\
		"[WARN] ",	\
		"[ERROR]   ",	\
		"[FATAL]   "	\
}

typedef enum tagIOType
{
	ennTOTYPE_INVALID	= 0,
	enmStdIO 			= 1,
	enmSYNC				= 2,	// ONLY for POSIX, otherwise the symbol is treated as enmStdIO
	enmNONBLOCK			= 3,
	enmStderr			= 4,
	enmIOTYPE_END
}IOType;

#ifdef __cplusplus
extern "C" {
#endif
/* Log file name pattern: cszLogFilePrefix_yyyymmdd.log*/
int32_t WriteLog( const char* 	cszLogFilePrefix,
			  	  IOType 		io,
			  	  LogLevel 		enmLogLv,
			  	  const char* 	cszFormat,
			  	  ...);

int32_t VWriteLog( const char* 	cszLogFilePrefix,
				  IOType		io,
				  LogLevel		enmLogLv,
				  const char*	cszFormat,
				  va_list		argp	);

LogLevel StrToLogLevel(const char* cszlogLevel);

#ifdef __cplusplus
}
#endif

#endif /* LOGAPI_H_ */
